<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$gametype = intval(getvar("gametype"));
if ($curruser['prev_id'] != 0)
{
    exit();
}
$gType = chkGametype($gametype);
switch ($gType)
{
    case 0 :
        $ui = new UI();
        include( "admin_menu.php" );
        break;
    default :
        include_once( "class_3d/CheckMode_3d.php" );
        $chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
        $chk->checkShow3dPage();
        unset($chk);
        $ui = new UI_3D();
        $jslink = "<script language=\"JScript.Encode\" src=\"site.js\"></script>" . ( "<script language=\"VBScript.Encode\" src=\"site.vbs\"></script>" ) . "<script src=\"core/tpl/k2/jquery-1.4.2.min.js\"></script>";
        $ui->set("jslink", $jslink);
        $ui->header();
        include( "admin_menu_3d.php" );
        break;
}
$sql = "SELECT id," . ( " ((SELECT COUNT(*) FROM bet Where user_id = K.id)" ) . " +(SELECT COUNT(*) FROM xbet_3d Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_3t Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_3s1 Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_3s2 Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_3s3 Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_3s4 Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_3s5 Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_3s6 Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_5h Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_8h Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_8h2 Where user_id = K.id)" . " +(SELECT COUNT(*) FROM xbet_8h3 Where user_id = K.id)" . " ) as cc FROM k_user K WHERE enabled=0 AND (SELECT COUNT(*) FROM k_user WHERE `prev_id`=K.`id`)=0 AND (IFNULL(`lastlogdt`,0) < UNIX_TIMESTAMP()-(86400*30)) HAVING cc=0";
$rs = getdb("SELECT count(*) FROM ({$sql}) AS AA");
if ($rs->f[0] == 0)
{
    diemsg("查无可删除停用的会员资料！");
}
if (isset($_POST['ok']))
{
    getdb("delete FROM k_user WHERE id IN (SELECT id FROM ({$sql}) AS AA)");
    getdb("delete FROM `amounts` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3d` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3t` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3s1` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3s2` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3s3` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3s4` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3s5` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_3s6` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_5h` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_8h` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_8h2` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    getdb("delete FROM `amounts_8h3` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
	getdb("delete FROM `amounts_sb1` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
	getdb("delete FROM `amounts_sb2` WHERE `user_id`>1 and `user_id` not in (Select id from k_user)");
    echo "<p>停用的资料已删除完成!</p>";
}
else
{
    echo "<font color=red><b>删除停用的资料(共:{$rs->f[0]} 笔)</b></font><br>";
    echo "<form action=\"op.php?op=admin&fp=delemember&gametype={$gametype}\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
    echo "<p>确定删除停用的资料？</p>";
    echo "<input type=hidden name=ok value=1>";
    echo "<p><input type=submit value=确定> <input type=button value=放弃 onclick=\"location.href='op.php?op=admin&fp=delemember&gametype={$gametype}'\">";
    echo "</form>";
}
$ui->footer();
?>